package com.datuo.dtf.common.exception;

import com.datuo.dtf.common.http.HttpStatus;

public class BaseServiceException extends RuntimeException {

    private int code;

    public BaseServiceException(String msg) {
        super(msg);
        this.code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    }

    public BaseServiceException(int code, String msg) {
        super(msg);
        this.code = code;
    }

    public static void assertError(boolean condition, String msg) {
        if (condition) {
            throw new BaseServiceException(msg);
        }
    }

    public static void assertError(boolean condition, int code, String msg) {
        if (condition) {
            throw new BaseServiceException(code, msg);
        }
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
}
